package com.company;

import java.util.Scanner;

public class demo34 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int n = sc.nextInt();
        System.out.println("1到"+n+"之间的素数有");
        for (int i = 1; i <= n; i++) {
            if (IsPrime(i)) {
                System.out.print(i + "\t");
            }
        }
    }

    static boolean IsPrime(int x) { //判断是否是素数
        boolean b = false;
        int i;
        for (i = 2; i < x; i++) {
            if (x % i == 0) {
                break;
            }
        }
        if (i == x) {
            b = true;
        }
        return b;
    }
}
